package com.neu.tlias.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.neu.tlias.pojo.Emp;
import com.neu.tlias.pojo.Result;
import com.neu.tlias.service.IEmpService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@Slf4j
@RestController
@RequiredArgsConstructor
public class LoginController {

    private final IEmpService empService;

    @PostMapping("/login")
    public Result login(HttpServletRequest request, @RequestBody Emp emp){
        log.info("员工登录:{}",emp);
        LambdaQueryWrapper<Emp> queryWrapper = new LambdaQueryWrapper<Emp>()
                .eq(Emp::getUsername,emp.getUsername())
                .eq(Emp::getPassword,emp.getPassword());
        Emp e = empService.getOne(queryWrapper);

        if(e == null){
            return Result.error("登录失败");
        }
        //request.getSession().setAttribute("employee",emp.getId());
        return Result.success(e);

    }
}
